package com.wao.classification.service.mapper;

import com.wao.classification.domain.Category;
import com.wao.classification.service.dto.CategoryDTO;
import com.wao.classification.service.dto.CategoryTreeDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

/**
 * Mapper for the entity Category and its Tree DTO CategoryTreeDTO.
 */
@Mapper(componentModel = "spring", uses = {})
public interface CategoryTreeMapper extends EntityMapper <CategoryTreeDTO, Category> {

    @Mapping(source = "parent.id", target = "parentId")
    CategoryTreeDTO toDto(Category category);

    @Mapping(source = "parentId", target = "parent")
    Category toEntity(CategoryTreeDTO categoryDTO);
    default Category fromId(Long id) {
        if (id == null) {
            return null;
        }
        Category category = new Category();
        category.setId(id);
        return category;
    }
}
